package com.k8.common.aop;

import com.k8.common.annotation.SPI;
import com.k8.common.aop.internal.advisor.Advisor;
import com.k8.common.extension.Adaptive;
import com.k8.rpc.url.URL;

import java.lang.reflect.Method;
import java.util.List;

import static com.k8.common.constants.CommonKeyConstants.PROXY_KEY;
import static com.k8.common.constants.SpiConstants.PROXY_TYPE_JAVASSIST;

/**
 * 由于接口动态代理成对应类然后使用拦截器拦截
 */
@SPI(PROXY_TYPE_JAVASSIST)
//todo
public interface ProxyFactory {
    Object build(Object target, List<Advisor> cacheAdvisors);

    @Adaptive({PROXY_KEY})
    Object build(URL url, Object target, List<Advisor> cacheAdvisors);

    //没有执行链Method，只是简单的拦截，是对特殊的不属于beanfactory管理的接口代理提供的方法
    <T> T createInterfaceProxy(Class<T> interfaceClazz, InterfaceProxyMethodInterceptor interceptor);

    <T> T createInterfaceProxy(Class<T> interfaceClazz, ClassLoader classLoader, InterfaceProxyMethodInterceptor interceptor);

    //todo 提供最简单的拦截器接口,只支持对接口的代理的拦截
    interface InterfaceProxyMethodInterceptor {
        Object process(Object proxy, Method method, Object[] args);
    }
}
